<template>
	<view class="main">
		<view class="top"></view>
		<van-nav-bar title="提问题" left-text="取消" right-text="发布问题" bind:click-left="onClickLeft"
			bind:click-right="onClickRight" />
		<view class="input">
			<input type="text" placeholder="请输入问题 (5~30个字)">
		</view>
		<view class="textarea">
			<textarea name="" placeholder="添加描述和配图(选填)"></textarea>
		</view>
		<view class="image">
			<view v-for="i in images" :key="i" class="imagelist">
				<image style="width: 150rpx;height: 150rpx;" :src="i" mode=""></image>
			</view>
			<view class="" @click="upload" v-if="isShowChooseImg">
				<view class="upload">
					<van-icon name="plus" size="20px" color="#ccc" />
				</view>
			</view>
		</view>
		<view class="foot-tools">
			<view class="huati">
				<view class="">
					<view class="cotent">
						<van-icon name="plus" />话题(至少添加一个)</van-icon>
					</view>
				</view>
			</view>
			<view class="tools-bar">


				<view class="tools-bar-left">
					<view class="img" @click="switchImg">
						<van-icon name="photo-o" :color="isShowChooseImg ? '#289958' : ''" />
					</view>
					<!-- <view class="location">
						<van-icon name="location-o" />长沙
					</view> -->
				</view>
				<!-- <view class="tools-bar-submit">
					发布
				</view> -->
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				images: [],
				isShowChooseImg: false
			}
		},
		methods: {
			upload() {
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: 'https://www.szzn.group/api/login/upload',
							// header:{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJhdWQiOiIiLCJpYXQiOjE2NjY4NDIwNjUsIm5iZiI6MTY2Njg0MjA2NSwiZXhwIjoxNjY5NDM0MDY1LCJqdGkiOnsiaWQiOjIxLCJ0eXBlIjoicm91dGluZSJ9fQ.Ztw4dETKy4goL9mskjNFtjTRa8V24IlahKMURaq8GUk"},
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'user': 'test' //
							},
							success: (uploadFileRes) => {
								this.image = uploadFileRes.data
								this.image = JSON.parse(this.image)

								this.images.push(this.image.data.url)
								console.log(this.images)
							}
						});
					}
				});
			},
			switchImg() {
				this.isShowChooseImg = !this.isShowChooseImg
			},
		}
	}
</script>

<style lang="scss">
	.main {
		padding: 15rpx;
	}

	.top {
		margin-top: 40rpx;
	}

	.input {
		border-bottom: 1px solid #eee;
		padding: 20rpx 5rpx;
		font-size: 30rpx;
	}

	.textarea {
		font-size: 26rpx;

		textarea {
			padding: 20rpx;
			width: 680rpx;
		}
	}

	.image {
		display: flex;
		flex-wrap: wrap;
	}

	.imagelist {
		margin: 0 10rpx;
	}

	.upload {
		width: 150rpx;
		text-align: center;
		height: 150rpx;
		line-height: 150rpx;
		background-color: #eee;
		font-size: 28rpx;
	}

	.foot-tools {
		position: fixed;
		bottom: 0;
		left: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		background-color: #fff;
		.huati {
			padding:30rpx;
			box-shadow: 0 -1px 5px 1px #eee;
			.cotent {
				font-size: 26rpx;
				background-color: #f6f6f6;
				border-radius: 50px;
				padding: 10rpx 25rpx;
				width:280rpx;
				text-align: center;
				color: #ccc;
			}
		}
		.tools-bar {
			width: 750rpx;
			box-sizing: border-box;
			padding: 20rpx 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-top: 1px solid #eee;
			border-bottom: 1px solid #eee;

			&-left {
				display: flex;

				.location {
					margin-left: 20rpx;
				}
			}

			&-submit {
				background-color: #289958;
				padding: 4rpx 40rpx;
				border-radius: 20px;
				color: #fff;
				font-size: 15px;
			}
		}
	}

	::v-deep van-nav-bar {
		margin-top: 100rpx !important;
	}
</style>
